Skip to content

Conversation

manerlan
Copy link
Member

@manerlan manerlan commented Nov 26, 2026 •

Closes #129

What

/mine/favoritter, /mine/vil-prove and /mine/har-provd can be sorted with a «Sorter etter» select:

Option ?sortering= API sort
Sist lagt til (default) (none) NEWEST
Din dom din-dom OWN_RATING
Best vurdert best-vurdert COMMUNITY_RATING
Navn A–Å navn NAME
  • URL: the order is stored in the URL, like on /mine/dommer, so it survives a reload. An unknown value falls back to the default.
  • History: changing the order replaces the history entry, so the back button leaves the page.
  • Back link: «Tilbake til listen» on the wine page keeps the order. The values only use characters the wine page's back link accepts.
  • Wines without a review: with «Din dom», they come last, newest added first (see docs/api.md).
  • Empty list: no select is shown.
  • Live region: after a list or a new order has loaded, it says e.g. «7 viner, sortert etter navn». A removed wine is still announced first.

Also fixes lost arrow-key presses in the order select on /mine/dommer (see below).

Builds on the API from #128.

How

  • listSort.ts: the options, their labels and their URL values, with parse and serialise functions.
  • Order in state: MyListPage and MyReviewsPage keep the order in state, and read it from the URL when the page opens. React Router updates the URL in a transition, so a select bound only to the URL was reset by React until then. Quick arrow-key presses were lost, and the Playwright test caught it. On the list pages, key={info.slug} gives each list its own state.
  • Apollo cache: keyArgs for User.wines is now ['list', 'sort', 'minRating'], so each order is cached apart.
  • Default order shares the cache: useMyWineList leaves out NEWEST (the API default). The default order then stays in the same cache entry as «Min side», and its first four wines still show at once.
  • updateListPages: already handled every order of a list. A wine taken off a list leaves every order, and a list a wine joined is fetched again in every order. This is now covered by a test.

Tests

  • MyListPage.test.tsx:
    • the four options
    • the order from the URL (as after a reload)
    • an unknown value
    • changing the order: URL, focus kept on the select, live region
    • Tab reaches the select right after the back link
    • the back button leaves the page after several changes
    • going back to the default order is served from the cache
    • «Last inn flere» in the chosen order
    • axe with an order chosen
  • apollo.test.ts: each order is cached apart, and a list without a sort is stored where «Min side» finds it.
  • listCache.test.ts: every order of a list is updated.
  • listSort.test.ts: the URL values round-trip, and they match what the wine page's back link accepts.
  • e2e/lists.spec.ts: the arrow keys change the order (three presses in a row), the order survives a reload, back goes to «Min side», and no axe violations. The fake API can now sort by name.
  • e2e/profile.spec.ts: on /mine/dommer, down and up in a row ends on «Nyeste først», the order is kept in the URL and survives a reload, and back goes to «Min side». The fake API now returns two reviews for /mine/dommer, in the order asked for. No other e2e test uses that page.

Docs

  • docs/api.md: the «Min side» table has the orders and their URL values, there is a row for listSort.ts, and keyArgs is updated.
  • docs/manual-testing.md: five new steps.

How to test

  1. npm run check, and npx playwright test e2e/lists.spec.ts e2e/profile.spec.ts in frontend/.
  2. Log in as demo and open «Se alle … du har prøvd».
  3. Tab to «Sorter etter» and use the arrow keys. The list changes, and focus stays on the select.
  4. Choose «Navn A–Å» and reload. The list is still sorted by name.
  5. Open a wine, then press «Tilbake til listen». The list is still sorted by name.
  6. Press the browser's back button. It goes to «Min side», not to the previous order.
  7. On /mine/dommer, press the arrow keys quickly in the select. No press is lost.

Review notes

  • Frontend only. No backend changes.
  • The axe test on «Min side» (MyPage.test.tsx), and maybe others, can time out on a busy machine, as it runs axe twice in one test. It passes in npm run check, and can be handled in a separate PR.

AI

Claude used to create code and tests based on prompt, manually tested and checked that npm run check and npm run e2e goes through. Claude created PR text for easy summary, but have gone over and made some updates manually.

@manerlan manerlan requested a review from a team as a code owner November 26, 2026 13:52
@manerlan manerlan linked an issue Nov 26, 2026 that may be closed by this pull request
4 tasks
Copy link
Member

@siverne siverne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran lists.spec.ts and profile.spec.ts on my Mac: 18 passed, 2 failed. The two new tests fail on desktop, and pass on mobile:

  • lists.spec.ts:115: the URL stays /mine/vil-prove after three ArrowDown presses.
  • profile.spec.ts:103: the URL stays /mine/dommer after ArrowDown.

On macOS, Chrome opens the menu of a native select on ArrowDown instead of changing the value, so the value never changes. On Windows and Linux it changes at once, which is probably why it passes for you. If staff run the tests on a Mac, they will fail.

A suggestion: keep the reload, URL and back-button checks for every platform with selectOption, and only run the fast arrow-key part where the keys change the value, e.g. test.skip(process.platform === 'darwin' && !isMobile, 'On macOS, arrow keys open a native select'). The unit tests already cover the order logic.

The rest looks good: the order in state fixes the same lost-update problem as the filter checkboxes in #68, the cache keeps each order apart, and updateListPages still finds the list name with sort in the key.

Not blocking:

  • The same six-line comment is in MyListPage.tsx and MyReviewsPage.tsx. One could just point to the other.
  • The live region now speaks after every load, also after «Last inn flere», where focus already moves. A bit chatty for screen readers.

@manerlan
Copy link
Member Author

Should all be fixed in commit b335b4e: the reload/URL/back checks now use selectOption and run everywhere, and the arrow-key part is a separate test skipped on macOS desktop (e2e/support/select.ts). Also shortened the duplicate comment, and the live region now only speaks after a change of order, not after the first load or «Last inn flere». All tests still go through on my end both npm run check and npx playwright test e2e/lists.spec.ts e2e/profile.spec.ts in frontend.

@siverne siverne self-requested a review November 26, 2026 14:56
Copy link
Member

@siverne siverne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled b335b4e and ran lists.spec.ts and profile.spec.ts on my Mac: 22 passed, 2 skipped (the arrow-key tests on desktop, as intended). Approving!

Splitting the tests works well: the URL, reload and back-button checks now run everywhere with selectOption, and the arrow-key race is still tested where the keys change the value. The quieter live region and the shorter comment in MyReviewsPage.tsx look good too.

@siverne siverne merged commit 80e754d into main Nov 26, 2026
@siverne siverne deleted the 129-sorting-min-side branch November 26, 2026 14:57
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sorting on the list pages on "Min Side"
2 participants